<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<script type="text/javascript">
	var shopGoodsCategoryDataGrid;
    $(function() {
        shopGoodsCategoryDataGrid = $('#shopGoodsCategoryDataGrid').datagrid({
        url : '${path}/shopGoodsCategory/dataGrid',
        striped : true,
		rownumbers : true,
		pagination : true,
		singleSelect : true,
		fitColumns:false,
	    idField : 'categoryId',
		sortName : 'categoryId',
		sortOrder : 'asc',
		pageSize : 20,
		pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,400, 500 ],
		frozenColumns : [ [	
						   {
            width : '140',
            title : '分类编号 ',
            field : 'categoryId',
            sortable : true
        }, 
								   {
            width : '140',
            title : '分类名称',
            field : 'categoryName',
            sortable : true
        }, 
								   {
            width : '140',
            title : '父级分类编号',
            field : 'categoryParentId',
            sortable : true
        }, 
								   {
            width : '140',
            title : '排序',
            field : 'categorySort',
            sortable : true
        }, 
								   {
            width : '140',
            title : '分类关键字',
            field : 'categoryKeyword',
            sortable : true
        }, 
								   {
            width : '140',
            title : '分类图片',
            field : 'categoryImage',
            sortable : true
        }, 
								   {
            width : '140',
            title : '推荐标志0-不推荐 1-推荐到首页',
            field : 'categoryCommend',
            sortable : true
        }, 
								   {
            width : '140',
            title : '默认标志，0-非默认 1-默认',
            field : 'categoryDefault',
            sortable : true
        }, 
				        {
            field : 'action',
            title : '操作',
            width : 200,
            formatter : function(value, row, index) {
                var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsCategory-easyui-linkbutton-search" data-options="plain:true,iconCls:\'icon-search icon-blue\'" onclick="shopGoodsSecondCategorySearchFun(\'{0}\');" >列表</a>', row.categoryId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsCategory-easyui-linkbutton-add" data-options="plain:true,iconCls:\'fi-plus icon-blue\'" onclick="shopGoodsSecondCategoryAddRelateFun(\'{0}\');" >添加</a>', row.categoryId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsCategory-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="shopGoodsCategoryEditFun(\'{0}\');" >编辑</a>', row.categoryId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsCategory-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="shopGoodsCategoryDeleteFun(\'{0}\');" >删除</a>', row.categoryId);
	                return str;
            }
        } ] ],
        onLoadSuccess:function(data){
            $('.shopGoodsCategory-easyui-linkbutton-search').linkbutton({text:'列表'});
            $('.shopGoodsCategory-easyui-linkbutton-add').linkbutton({text:'新增'});
            $('.shopGoodsCategory-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.shopGoodsCategory-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#shopGoodsCategoryToolbar'
    });
});

/**
 * 一级分类添加框
 * @param url
 */
function shopGoodsCategoryAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : 700,
        height : 600,
        href : '${path}/shopGoodsCategory/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = shopGoodsCategoryDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#shopGoodsCategoryAddForm');
                f.submit();
            }
        } ]
    });
}

/**
*二级分类添加框
**/
function shopGoodsSecondCategoryAddRelateFun(id){
   parent.$.modalDialog({
        title : '二级分类添加',
        width : 700,
        height : 600,
        href : '${path}/shopGoodsCategory/addSecondCategoryPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = shopGoodsCategoryDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#shopGoodsSecondCategoryAddForm');
                f.submit();
            }
        } ]
    });

}
/**
*二级分类信息查询
**/
function shopGoodsSecondCategorySearchFun(id){
    parent.$.modalDialog({
        title : '二级分类列表',
        width : 1400,
        height : 600,
        href :  '${path}/shopGoodsCategory/secondCategoryPage?id=' + id
    });
}

/**
 * 编辑
 */
function shopGoodsCategoryEditFun(id) {
    if (id == undefined) {
        var rows = shopGoodsCategoryDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        shopGoodsCategoryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : 700,
        height : 600,
        href :  '${path}/shopGoodsCategory/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = shopGoodsCategoryDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#shopGoodsCategoryEditForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 删除
 */
 function shopGoodsCategoryDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = shopGoodsCategoryDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         shopGoodsCategoryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/shopGoodsCategory/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     shopGoodsCategoryDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}


/**
 * 清除
 */
function shopGoodsCategoryCleanFun() {
    $('#shopGoodsCategorySearchForm input').val('');
    shopGoodsCategoryDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function shopGoodsCategorySearchFun() {
     shopGoodsCategoryDataGrid.datagrid('load', $.serializeObject($('#shopGoodsCategorySearchForm')));
}
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',border:false"
		style="height: 30px; overflow: hidden;background-color: #fff">
		<form id="shopGoodsCategorySearchForm">
			<table>
				<tr>
					<th>名称:</th>
					<td><input name="name" placeholder="搜索条件" />
					</td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-magnifying-glass',plain:true"
						onclick="shopGoodsCategorySearchFun();">查询</a> <a
						href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-x-circle',plain:true"
						onclick="shopGoodsCategoryCleanFun();">清空</a></td>
				</tr>
			</table>
		</form>
	</div>

	<div data-options="region:'center',border:false">
		<table id="shopGoodsCategoryDataGrid"
			data-options="fit:true,border:false"></table>
	</div>
</div>
<div id="shopGoodsCategoryToolbar" style="display: none;">
	<a onclick="shopGoodsCategoryAddFun();" href="javascript:void(0);"
		class="easyui-linkbutton"
		data-options="plain:true,iconCls:'fi-plus icon-green'">一级分类添加</a>
</div>